package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.ShoppingCartItem;

public class CheckoutServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public CheckoutServlet() {
		super();
	}


	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
    	ArrayList<ShoppingCartItem> list = new ArrayList<ShoppingCartItem>();
    	Double total = (Double) session.getAttribute("total");
    	request.setAttribute("total", total);
    	session.setAttribute("cart", list);
    	session.setAttribute("nbrOfItems", 0);
    	session.setAttribute("total", 0);
    	
    	RequestDispatcher rd = request.getRequestDispatcher("checkout.jsp");
    	rd.forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}


	public void init() throws ServletException {
		// Put your code here
	}

}
